#define _CRT_SECURE_NO_WARNINGS 1
#include"Stack.h"
void stackInit(Stack* pst)
{
	assert(pst);
	pst->data = NULL;
	pst->size = pst->capacity = 0;
}
void stackDestroy(Stack* pst)
{
	assert(pst);
	if(pst->data)
		free(pst->data);
	pst->capacity = pst->size = 0;
	pst->data = NULL;
}
void cheakCapacity(Stack* pst)
{
	assert(pst);
	if (pst->size == pst->capacity)
	{
		int newcapacity = pst->capacity == 0 ? 4 : 2 * pst->capacity;
		StackDataType* temp = (StackDataType*)realloc(pst->data, sizeof(StackDataType) * newcapacity);
		if (temp == NULL)
		{
			perror("realloc error");
			exit(1);
		}
		pst->data = temp;
		pst->capacity = newcapacity;
	}
}
int stackEmpty(Stack* pst)
{
	assert(pst);
	return pst->size==0;
}
void stackPush(Stack* pst, StackDataType data)
{
	assert(pst);
	cheakCapacity(pst);
	pst->data[pst->size++] = data;
}
void stackPop(Stack* pst)
{
	assert(pst);
	assert(!stackEmpty(pst));
	pst->size--;
}
StackDataType stackTop(Stack* pst)
{
	assert(pst);
	assert(!stackEmpty(pst));
	return pst->data[pst->size - 1];
}
int stackSize(Stack* pst)
{
	assert(pst);
	return pst->size;
}